#include <bits/stdc++.h>
using namespace std;
int T;
double x[100005],y[100005];
int w[100005];
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
void write(int x)
{
    if(x<0)
    {
        x=-x;
        putchar('-');
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
struct node{
    double x,y;
}k[100005];
struct node2{
    int x,y;
}jl[100005];
bool vis[100005];
struct node3{
    int siz;
    vector <int> g;
}d[100005];
bool cmp(node3 v1,node3 v2)
{
    return v1.siz<v2.siz;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T--)
    {
        memset(vis,0,sizeof(vis));
        int ans1=0,ans2=0;
        int n=read(),m=read();
        int xx=read();
        double L=double(xx);
        xx=read();
        double V=double(xx);
        for(int i=1;i<=n;i++)
        {
            xx=read();
            double d=double(xx);
            xx=read();
            double v=double(xx);
            xx=read();
            double a=double(xx);
            if(v<=V && a<=0)
            {
                k[i]={-1,-1};
                continue;
            }
            if(v>V && a>=0)
            {
                k[i]={d,L};
                continue;
            }
            int t;
            if(v>V)
            {
                t=(V*V-v*v)/(a*2)-0.0001;
                k[i]={d,d+t};
            }

            if(v<V)
            {
                t=(V*V-v*v)/(a*2)+0.0001;
                k[i]={d+t,L};
            }
        }
        for(int i=1;i<=n;i++)
           jl[i].x=int(k[i].x),jl[i].y=int(k[i].y);
        //for(int i=1;i<=n;i++)
        //    cout<<jl[i].x<<' '<<jl[i].y<<endl;
        for(int i=1;i<=m;i++)
            w[i]=read();
        for(int i=1;i<=n;i++)
        {
            bool f=0;
            for(int j=1;j<=m;j++)
            {
                if(w[j]>=jl[i].x && w[j]<=jl[i].y)
                {
                    f=1;
                    d[i].g.push_back(w[j]);
                    d[i].siz++;
                }
            }
            if(f)
                ans1++;
        }/*
        sort(d+1,d+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<d[i].g.size();j++)
                cout<<d[i].g[j]<<' ';
            cout<<endl;
        }*/
        for(int i=1;i<=n;i++)
        {
            bool f=0;
            for(int j=0;j<d[i].g.size();j++)
            {
                if(vis[d[i].g[j]])
                {
                    f=1;
                    break;
                }
            }
            if(!f)
            {
                ans2++;
                vis[d[i].g[0]]=1;
            }
        }
        write(ans1);putchar(' ');write(ans2);puts("");
    }
    return 0;
}
